package my.framework.ssm.sample.common.controller;

import my.framework.ssm.sample.common.entity.NonNullDTO;
import my.framework.ssm.sample.common.enums.ResultEnum;

/**
 * api响应对象
 *
 * @author NuKi
 * @date 2018/11/24 14:59
 */
public class Result<T> extends NonNullDTO {
    private String code;
    private String msg;

    private T data;

    public Result() {
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Result(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMessage();
    }

    public static Result suc() {
        return new Result(ResultEnum.SUCCESS);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result error(String code, String msg) {
        return new Result(code, msg);
    }
}
